﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CCWin;

namespace HotelManager.Views
{
    public partial class Form_CheckIn : Skin_DevExpress
    {
        public Form_CheckIn()
        {
            InitializeComponent();
        }

        public string RoomNum = string.Empty;

        private void Form_CheckIn_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(RoomNum))
            {
                skinTextBox4.Text = RoomNum;
                skinTextBox5.Text =
                    DB.GetData("select 押金 from 房间状态表,房间类型表 where 房间状态表.房间号='"
                    + RoomNum + "' and 房间状态表.类型ID = 房间类型表.类型ID").ToString();
            }
            skinDateTimePicker1.text = DateTime.Now.ToString("yyyy-MM-dd");
            skinComboBox1.SelectedIndex = 0;
        }

        private void skinButton1_Click(object sender, EventArgs e)
        {
            if (skinTextBox1.Text == string.Empty || skinTextBox2.Text == string.Empty ||
                skinTextBox3.Text == string.Empty || skinTextBox4.Text == string.Empty ||
                skinTextBox5.Text == string.Empty || (!skinRadioButton1.Checked && !skinRadioButton2.Checked))
            {
                MessageBox.Show("请补全信息！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            string sql1 = string.Format(@"insert into 客户入住表(姓名,性别,证件类别,证件号码,电话号码,房间号,入住时间,入住天数,押金,备注)
                                        values('{0}', '{1}', '{2}', '{3}', '{4}', {5}, '{6}', {7}, {8}, '{9}')",
                                        skinTextBox1.Text,
                                        skinRadioButton1.Checked ? "男" : "女",
                                        skinComboBox1.Text,
                                        skinTextBox2.Text,
                                        skinTextBox3.Text,
                                        skinTextBox4.Text,
                                        skinDateTimePicker1.text,
                                        numericUpDown1.Value.ToString(),
                                        skinTextBox5.Text,
                                        skinTextBox6.Text);
            string sql2 = string.Format("update 房间状态表 set 是否空='否',是否预订='否' where 房间号="+skinTextBox4.Text);
            DB.Execute(sql1);
            DB.Execute(sql2);
            MessageBox.Show("入住房间成功！", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
        }

        private void skinButton2_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
